import type {BaseRsp, DelParamsType, ListData, PageParamsType} from "@/api/index";
import {useAxios} from "@/api/index";

// 查询菜单列表
export interface MenuRsp {
    id: number
    created_at: Date
    updated_at: Date
    title: string
    path: string
    slogan: string
    abstract: string
    abstract_time: string[]
    image_time: number
    sort: number
    image_list: Menu2ImageRsp[]
}

export interface Menu2ImageRsp {
    image_id: number
    image_name: string
    image_path: string
    sort: number
}

export function menuListAxios(params: PageParamsType): Promise<BaseRsp<ListData<MenuRsp>>> {
    return useAxios.get("/admin/menu/list", {params})
}


// 添加菜单
export interface MenuAddReq {
    title: string
    path: string
    slogan: string
    abstract: string[]
    abstract_time: number
    image_time: number
    sort: number
    image_id_list: number[]
}

export function menuAddAxios(params: MenuAddReq): Promise<BaseRsp<boolean>> {
    return useAxios.post("/admin/menu/add", params)
}


// 更新菜单
export interface MenuUpdateReq {
    id: number
    title: string
    path: string
    slogan: string
    abstract: string[]
    abstract_time: number
    image_time: number
    sort: number
    image_id_list: number[]
}


export function menuUpdateAxios(params: MenuUpdateReq): Promise<BaseRsp<boolean>> {
    return useAxios.put("/admin/menu/update", params)
}

// 删除菜单
export function menuDelAxios(params: DelParamsType): Promise<BaseRsp<boolean>> {
    return useAxios.delete("/admin/menu/del", {data: params})
}
